﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MapperVerificationTests
{
    public class When_mapping_between_arrays_of_primitive_types
    {
        public class DomainPerson
        {
            public int[] Ids { get; set; }
        }
        public class GuiPerson
        {
            public int[] Ids { get; set; }
            public int[] PropertyThatThrowsException { get { return new int[0];} set{ throw new Exception("I Throw!");} }

            public int[] PropertyThatDoesntSet { get { return null; } set { return; } }
        }

        [Fact]
        public void Should_verify_normal_cases()
        {
            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain=>domain.Ids,gui=>gui.Ids);
            var verifier = mapping.GetMapperVerification();

            verifier.AssertMapsCorrectlyTowards(new GuiPerson());
        }

        [Fact]
        public void Should_not_verify_when_setter_throws_exception()
        {
            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.Ids, gui => gui.PropertyThatThrowsException);
            var verifier = mapping.GetMapperVerification();

            Assert.Throws(typeof(GlueException), () => verifier.AssertMapsCorrectlyTowards(new GuiPerson()));
        }

        [Fact]
        public void Should_not_verify_when_setter_doesnt_set()
        {
            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.Ids, gui => gui.PropertyThatDoesntSet);
            var verifier = mapping.GetMapperVerification();

            Assert.Throws(typeof(GlueException), () => verifier.AssertMapsCorrectlyTowards(new GuiPerson()));
            
        }
    }
}
